package com.dushibao.web.user;

import com.alibaba.fastjson.JSON;
import com.dushibao.entity.User;
import com.dushibao.service.UserService;
import com.dushibao.service.impl.UserServiceImpl;
import com.dushibao.util.ResultUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/user/add")
public class AddServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader bw = req.getReader();
        String json = bw.readLine();

        User user = JSON.parseObject(json, User.class);

        Integer ret = userService.saveOrUpdate(user);

        resp.getWriter().write(ResultUtils.success(ret));

    }
}
